<template>
<el-card>
    <el-table :data="list" border :header-cell-style="tableHeader" v-loading="loadingTable">
        <el-table-column v-for="item in columns" :label="item.title" align="center" :min-width="item.width"  :key="item.dataKey">
            <template #default="scope">
                <el-link type="primary" v-if="scope.row['have_secondary_account'] && item.dataKey=='have_secondary_account'" @click="goTo({business_id:scope.row['business_id']})"> 去看看</el-link>
                <span v-else>{{  scope.row[item.dataKey] || '-' }}</span>
            </template>
        </el-table-column>
    </el-table>
</el-card>
</template>
<script setup lang="ts">
import { onMounted } from 'vue';
import {tableHeader} from '@/utils/users/pubConfig';
import {businessAllocationPurchasePath} from '@/config/paths';
import type {Column} from '@/utils/users/pubConfig';
import router from "@/router";
import { useRoute } from 'vue-router';
const route = useRoute();
interface BusinessInfo{
    business_name:string,
    business_id:string,
    total_days:number,
    gift_days:number,
    gift10_ndays:number,
    total_pays:number,
    leave_days:number,
    allocation_days:number,
    used_days:number,
    return_days:number,
    allocation_users:number,
    averge_allocation_days:number,
    averge_used_days:number
}
const list=ref<BusinessInfo[]>([{
    business_name:'string',
    business_id:'string',
    total_days:0,
    gift_days:0,
    gift10_ndays:0,
    total_pays:0,
    leave_days:0,
    allocation_days:0,
    used_days:0,
    return_days:0,
    allocation_users:0,
    averge_allocation_days:0,
    averge_used_days:0
}])
const columns=ref<Column[]>([
    {
        key:'business_name',
        title:'企业名称',
        dataKey:'business_name'
    },
    {
        key:'have_secondary_account',
        title:'二级账号',
        dataKey:'have_secondary_account'
    },
    {
        key:'total_days',
        title:'总计天数',
        dataKey:'total_days'
    },
    {
        key:'gift_days',
        title:'赠送天数',
        dataKey:'gift_days'
    },
    {
        key:'gift10_ndays',
        title:'充10送N',
        dataKey:'gift10_ndays',
       
    },
    {
        key:'total_pays',
        title:'实付金额',
        dataKey:'total_pays'
    },
    {
        key:'leave_days',
        title:'剩余天数',
        dataKey:'leave_days'
    },
    {
        key:'allocation_days',
        title:'分配天数',
        dataKey:'allocation_days'
    },
    {
        key:'used_days',
        title:'实际使用天数',
        dataKey:'used_days'
    },
    {
        key:'return_days',
        title:'返还天数',
        dataKey:'return_days'
    },
    {
        key:'allocation_users',
        title:'分配人次',
        dataKey:'allocation_users'
    },
    {
        key:'averge_allocation_days',
        title:'平均每人分配天数',
        dataKey:'averge_allocation_days',
        width:'110'
    },
    {
        key:'averge_used_days',
        title:'人均消耗天数',
        dataKey:'averge_used_days'
    },

])
const postData=ref<{business_id:string}>({business_id:''})
const loadingTable=ref<boolean>(false)
onMounted(async()=>{
    const {business_id}=route.query
    // console.log('bussiness',business_id)
    postData.value.business_id=business_id
    loadingTable.value=true
    const {data}= await baseRequest.post(businessAllocationPurchasePath.value,postData.value)
    loadingTable.value=false
    list.value=[]
    list.value.push(data)
})

function goTo({business_id}){
    router.push({path:`/business/businessAllocationPurchase/secondaryAccount/${business_id}`,query:{business_id}})
}
</script>